package tongcheng.com.tongcheng.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import tongcheng.com.tongcheng.R;
import tongcheng.com.tongcheng.base.BaseViewHolder;
import tongcheng.com.tongcheng.bean.FuWuAreaBean;

/**
 * Created by P on 2017/7/26.
 */

public class FuwuAreaAdapter extends RecyclerView.Adapter<FuwuAreaAdapter.FuwuAreaViewHolder> {
    public Context mContext;
    public List<FuWuAreaBean.DataBean> data;

    public FuwuAreaAdapter(Context context, List<FuWuAreaBean.DataBean> data) {
        this.mContext = context;
        this.data = data;
    }

    @Override
    public FuwuAreaViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(mContext, R.layout.item_fuwuarea, null);

        FuwuAreaViewHolder fuwuAreaViewHolder = new FuwuAreaViewHolder(view);
        return fuwuAreaViewHolder;
    }

    @Override
    public void onBindViewHolder(final FuwuAreaViewHolder holder, final int position) {
        final FuWuAreaBean.DataBean fuWuAreaBean = data.get(position);

        holder.item_fuwuarea_text.setText(fuWuAreaBean.name);

        if (fuWuAreaBean.isCheck) {
            holder.item_fuwuarea_icon.setImageResource(R.mipmap.queding);
            holder.item_fuwuarea_text.setTextColor(ContextCompat.getColor(mContext,android.R.color.holo_red_light));
        } else {
            holder.item_fuwuarea_icon.setImageResource(R.mipmap.weixuanze);
            holder.item_fuwuarea_text.setTextColor(ContextCompat.getColor(mContext, R.color.dan_bloack));
        }


        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (fuWuAreaBean.isCheck==false) {
                    holder.item_fuwuarea_icon.setImageResource(R.mipmap.queding);
                    holder.item_fuwuarea_text.setTextColor(ContextCompat.getColor(mContext, android.R.color.holo_red_light));
                    fuWuAreaBean.isCheck = true;
                } else if (fuWuAreaBean.isCheck==true) {
                    holder.item_fuwuarea_icon.setImageResource(R.mipmap.weixuanze);
                    holder.item_fuwuarea_text.setTextColor(ContextCompat.getColor(mContext, R.color.dan_bloack));
                    fuWuAreaBean.isCheck = false;
                }
                Log.e("ischeck", fuWuAreaBean.isCheck + "");
            }
        });
    }

    @Override
    public int getItemCount() {
        return data==null?0:data.size();
    }

    public class FuwuAreaViewHolder extends BaseViewHolder{
        public LinearLayout item_fuwuarea_all;
        public ImageView item_fuwuarea_icon;
        public TextView item_fuwuarea_text;
        public FuwuAreaViewHolder(View itemView) {
            super(itemView);
        }

        @Override
        public void init(View itemview) {
            item_fuwuarea_all = itemview.findViewById(R.id.item_fuwuarea_all);
            item_fuwuarea_icon= itemview.findViewById(R.id.item_fuwuarea_icon);
            item_fuwuarea_text= itemview.findViewById(R.id.item_fuwuarea_text);
        }
    }


}
